#v1.0 version moved from lubanos to here, by Michael Zhang
host=`hostname`
if [ "$host"x = "mich"x ]; then
  project_base=/home/mich/BlacDevelopment/blacframework
else
  project_base=/home/luban/blac/blacframework
fi
logfile=$project_base/Application/aero_shape/sys_run.log
touch $logfile
ddir=/home/luban/discon/EIC002/aero/design
rm -f $ddir/*.*
python aero_design.py>$logfile 2>&1
rm /home/luban/NAS/inputs/blade_shape/*.*
cp $ddir/*.* /home/luban/NAS/inputs/blade_shape/
date>>$logfile
#echo '################### this is run_pre_streamlit.sh ####################'>>$logfile
#kill BadTh files
now=`pwd`
cd $ddir
#echo "design files dir is "`pwd`>>$logfile
ls -l |grep BadTh|awk '{print $9}'|xargs sudo rm -f
#sudo sed -i 's/,/./g' ./*.dat
cd $now
if [ $1 = "compare123" ];then
    if [ "$host" = "mich" ];then
      #echo 'this is mich pc'>>$logfile
      outdir=/home/mich/balcframework/Application/aero_shape/inputs/blade_shape_out
      dfiles=`ls /home/mich/discon/aero/design`
      ddir=/home/mich/discon/aero/design
      stand_js=`pwd`/inputs/standard-X/`ls ./inputs/standard-X`
    else
      echo 'this is luban server  '>>$logfile
      outdir=/home/luban/NAS/inputs/blade_shape_out
      dfiles=`ls /home/luban/discon/EIC002/aero/design`
      ddir=/home/luban/discon/EIC002/aero/design
      stand_js=/home/luban/NAS/inputs/standard-X/`ls ./inputs/standard-X`
    fi
  kind='linear'
  source_files=$ddir/*.*
  #echo $source_files>>$logfile
  #rm thickness < mim airfoil thicknesss
  num=`ls -l $source_files|wc -l`
  if [ "$num" -gt "3" ];then
    #echo ' design dir not empty'>>$logfile
    #echo "back to working dir "`pwd`>>$logfile
    #echo "ddir "$ddir>>$logfile
    #do transfer as a standard
    for file in $dfiles
      do
        file_with_path=$ddir/$file
        outfile=$outdir/$file
        if [ -d $outdir ]; then
          if [ $1 = "compare123" ];then
            #echo $file_with_path>>$logfile
            #echo 'this is compare 123'
            python blade_spline_multi.py --stand_x_json $stand_js --input_dir $file_with_path --output_dir $outfile --method $kind --compare123 "True"
          else
            echo 'this is not compare123, just shape gen only'
            python blade_spline_multi.py --stand_x_json $stand_js --input_dir $file_with_path --output_dir $outfile --method $kind --compare123 "False"
          fi
        else
          mkdir $outdir
          if [ $1 = "compare123" ];then
            #echo $file_with_path>>$logfile
            python blade_spline_multi.py --stand_x_json $stand_js --input_dir $file_with_path --output_dir $outfile --method $kind --compare123 "True"
          else
            python blade_spline_multi.py --stand_x_json $stand_js --input_dir $file_with_path --output_dir $outfile --method $kind --compare123 "False"
          fi
        fi
        #echo " --input_dir $file_with_path --output_dir $outfile --stand_x_json $stand_js">>$logfile
      done
    if [ "$host" = "mich" ];then
      #echo 'mich copy to blade_shape and res_blade '>>$logfile
      sudo cp $outdir/*.dat `pwd`/inputs/blade_shape
      if [ $1 = "compare123" ];then
        sudo cp $outdir/*.dat  `pwd`/inputs/res_blade/
      fi
    else
      #echo 'luban copy to blade_shape and res_blade '>>$logfile
      sudo cp $outdir/Ind*.dat /home/luban/NAS/inputs/blade_shape/
      if [ $1 = "compare123" ];then
        sudo cp $outdir/Ind*.dat /home/luban/NAS/inputs/res_blade/
      fi
    fi
    #echo '#################### all shape files done, update shape <<Aero_shape Generator>> on the left navigation menu to analysis shapes ##########'>>$logfile
    #date>>$logfile
  fi
fi
date>>$logfile
echo 'Done for init created shapes'>>$logfile